<html xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui" >  

    <!--    <h:body>-->
    <ui:composition template="layout.xhtml">-->

        <ui:define name="corpo">
            <h:form id="incluir_form_distribuicao" acceptcharset="utf-8"> 
                <p:panel header="Distribuir Selos">
                    <p:growl showDetail="true"  id="msg" />
                    <fieldset>
                        <legend>Dados do Recebedor</legend>
                        <br/>
                       
                    </fieldset>
                    <br/>
                    <fieldset>
                        <legend>Distribuição de Selos</legend> 
                        <h:panelGrid id="all" columns="2" width="900" styleClass="textAlignRight" columnClasses="textAlignRight"> 
                            <h:panelGrid columns="2"  id="panelSelos" styleClass="textAlignRight" columnClasses="textAlignRight"> 
                                <h:outputText value="Tipo Selo :"/>
                                <p:autoComplete id="tipoSelo" value="#{managerEntradaSelo.detalheEntradaSelo.tipoSelo}" completeMethod="#{managerTipoSelo.completeTipoSelo}"  
                                                var="p" itemLabel="#{p.nome}" itemValue="#{p}" converter="tipoSeloConverter" forceSelection="true" converterMessage="Erro, verifique o Tipo Selo" minQueryLength="3" dropdown="true" required="true" requiredMessage="O campo 'Tipo Selo' é obrigato"> 
                                    <p:ajax event="itemSelect" listener="#{managerEntradaSelo.handleSelectTipoSelo}"/>
                                </p:autoComplete>
                                
                                <h:outputText value="Serie :"/>
                                <p:inputText value="#{managerEntradaSelo.detalheEntradaSelo.serie}"/>
                                <h:outputText value="Preco :"/>
                                <p:inputText value="#{managerEntradaSelo.detalheEntradaSelo.preco}"/>
                                <h:outputText value="NUm inic :"/>
                                <p:inputText value="#{managerEntradaSelo.detalheEntradaSelo.numIni}"/>
                                <h:outputText value="NUm fim :"/>
                                <p:inputText value="#{managerEntradaSelo.detalheEntradaSelo.qtd}"/>
                                
                                
                               
                                <p:row>
                                    
                                    <p:commandButton value="Adicionar"  actionListener="#{managerEntradaSelo.addList()}" process="@this, panelSelos" update="distribuirSelos, panelSelos, msg" />
                                </p:row>
                            </h:panelGrid>
                            <p:dataTable var="dSelos" id="distribuirSelos" 
                                         value="#{managerEntradaSelo.lstDetalhe}"
                                         rowIndexVar="rowid"  emptyMessage="Nenhum selo adicionado">  
                                <f:facet name="header">  
                                    Resumo da Distribuição
                                </f:facet>  
                                <p:column headerText="Tipo Selo" style="text-align: center;">  
                                    <h:outputText value="#{dSelos.numIni}" />  
                                </p:column>
                                <p:column headerText="Tipo Selo" style="text-align: center;">  
                                    <h:outputText value="#{dSelos.preco}" />  
                                </p:column>
                                
                                <p:column headerText="Opc" style="width: 43px">  
                                    <p:commandButton  style="width: 20px; height: 20px;" actionListener="#{managerEntradaSelo.remove(dSelos)}"  icon="ui-icon-trash" process="@this" update="@form"/>
                                    <p:commandButton  style="width: 20px; height: 20px;" onclick="removeRC({param:#{rowid}})" icon="editar"/>
                                </p:column>

                            </p:dataTable>
                            <p:remoteCommand name="removeRC"
                                             update="distribuirSelos, all" process="@this" actionListener="#{managerEntrada.editar()}">

                                </p:remoteCommand>
                        </h:panelGrid>
                    </fieldset>
                    <br/>
                    <center>
                        <p:commandButton id="limpar" icon="ui-icon-close" actionListener="#{managerEntradaSelo.limpaList()}" value="limpar"  update="@form" immediate="true"/>  
                        <p:commandButton value="Distribuir" icon="ui-icon-transferthick-e-w"  actionListener="#{managerEntradaSelo.distribuir()}" onclick="statusDialog.show();" process="@this" update="@form, msg" />
                    </center>
                </p:panel>

                <p:dialog modal="true" widgetVar="statusDialog" header="Distribuindo Selos"   
                          draggable="false" closable="false">  
                    <p:graphicImage value="/media/img/ajaxloadingbar.gif" />  
                </p:dialog>

                <p:dialog modal="true" resizable="false"  widgetVar="dialog" width="450" minHeight="100" header="Entregar Selos" >

                    <!--                    <table style="border-width: 2px;">
                                            <ui:repeat value="{managerEntradaSelo.lsRd}" var="lstAll">
                                                <tr>
                                                    <td style="background-color: \#{lstAll.tipoSelo.corSelo.cor}"></td>
                                                    <td> <h:outputLabel value="lstAll.tipoSelo.descricao}" /></td>
                                                </tr>
                                                <ui:repeat value="{lstAll.selo}" var="lstselo">
                                                    <tr>
                                                        <td> <h:outputLabel value="#{lstselo.numero}" /></td>
                                                    </tr>
                                                </ui:repeat>
                                            </ui:repeat>
                                        </table>-->
                  
                    <f:facet name="footer" >
                        <center>
                            <p:commandButton value="Confirmar entrega" icon="ui-icon-circle-plus" actionListener="#{managerEntradaSelo.reinit()}" update="@form" immediate="true"/>
                            <p:commandButton value="Cancelar Distribuição" icon="ui-icon-circle-close" actionListener="#{managerEntrada.indexEntradaSelo()}" immediate="true"/>
                        </center>
                    </f:facet>
                </p:dialog> 

            </h:form>
        </ui:define>
    </ui:composition>
</html>

